﻿#region Usings

using System.Data.Entity.ModelConfiguration;
using Rail.Net.Core.Model;

#endregion

namespace Rail.Net.Data.Configuration
{
    public class PaymentOptionMap : EntityTypeConfiguration<PaymentOption>
    {
        public PaymentOptionMap()
        {
            ToTable("PaymentOptions");
            HasKey(paymentOption => paymentOption.Id);

            Property(paymentOption => paymentOption.Type).IsRequired();
            Property(paymentOption => paymentOption.Name).IsRequired().HasMaxLength(30);

            HasMany(paymentOption => paymentOption.Tariffs).WithMany(tariff => tariff.PaymentOptions).Map(
                m =>
                    {
                        m.ToTable("TariffPaymentOptions");
                        m.MapLeftKey("PaymentOption_Id");
                        m.MapRightKey("Tariff_Id");
                    });
        }
    }
}